<template>
  <div>
    <el-button type="primary" @click="dialogVisibles()">新增管理员</el-button>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="platformId" label="id"></el-table-column>
      <el-table-column prop="platformName" label="姓名"></el-table-column>
      <el-table-column prop="platformImage" label="照片">
        <template slot-scope="scope">
          <el-image :src="scope.row.platformImage" windex="100px" />
        </template>
      </el-table-column>
      <el-table-column prop="platformPhone" label="手机号"></el-table-column>
      <el-table-column prop="platformEmail" label="邮箱号"></el-table-column>
      <el-table-column prop="sex" label="性别">
        <template slot-scope="scope">
          <span v-if="scope.row.sex === 1">男</span>
          <span v-if="scope.row.sex === 2">女</span>
        </template>
      </el-table-column>
      <el-table-column prop="age" label="年龄"></el-table-column>
      <el-table-column prop="role" label="权限">
        <template slot-scope="scope">
          <span v-if="scope.row.role === 1">最高权限管理员</span>
          <span v-if="scope.row.role === 2">平台管理员</span>
          <span v-if="scope.row.role === 3">客服管理员</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="platformDelete(scope.row.platformId)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="TbPlatform" label-width="80px">
        <el-form-item label="管理员名称">
          <el-input v-model="TbPlatform.platformName"></el-input>
        </el-form-item>
        <el-form-item label="管理员手机号">
          <el-input v-model="TbPlatform.platformPhone"></el-input>
        </el-form-item>
        <el-form-item label="管理员邮箱">
          <el-input v-model="TbPlatform.platformEmail"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-radio-group v-model="TbPlatform.sex">
            <el-radio label="1">男</el-radio>
            <el-radio label="2">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model.number="TbPlatform.age"></el-input>
        </el-form-item>
        <el-form-item label="身份">
          <el-select v-model="TbPlatform.role" placeholder="请选择身份">
            <el-option label="最高权限管理员" value="1"></el-option>
            <el-option label="部分权限管理员" value="2"></el-option>
            <el-option label="客服管理员" value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="platformInsert()">确 定</el-button>
    </el-dialog>
  </div>
</template>

<script>
  import { platformselect, platformInsert, platformDeleted } from '@/api/users'
  export default {
    data() {
      return {
        tableData: [],
        dialogVisible: false,
        TbPlatform: {
          platformName: '',
          platformPhone: '',
          platformEmail: '',
          sex: '',
          age: '',
          role: '',
        },
      }
    },
    mounted() {
      this.platformselect()
    },
    methods: {
      platformselect() {
        platformselect().then((res) => {
          this.tableData = res.data
          console.log(res.data)
        })
      },
      dialogVisibles() {
        this.dialogVisible = true
      },
      platformInsert() {
        console.log(this.TbPlatform)
        platformInsert(this.TbPlatform).then((res) => {
          this.tableData = res.data
          console.log(res.data)
          this.dialogVisible = false
        })
      },
      platformDelete(row) {
        console.log(row)
        platformDeleted(row).then((res) => {
          console.log(res.data)
          if (res.code === 200) {
            this.platformselect()
          }
        })
      },
    },
  }
</script>
